package jEDF.Hypnogram;

import java.awt.*;

import javax.swing.*;

/**
 *
 * <p>Titre : jEDF</p>
 * <p>Description : Java European Data Format Viewer and Analyser</p>
 * <p>Author : Nizar Kerkeni</p>
 * <p>Copyright : Copyright (c) 2003-2006</p>
 * <p>Version 2.0</p>
 */

public class JEDFStagesPanel extends JPanel {
    private JLabel[] labels = new JLabel[8];


    /**
     * constructor
     */
    public JEDFStagesPanel() {
        setLayout(new GridLayout(1, 8));

        for (int i = 0; i < labels.length; i++) {
            labels[i] = new JLabel("---");
            if (i == (labels.length - 2)) {
                labels[i].setForeground(Color.RED);
            }
            labels[i].setBorder(BorderFactory.createEtchedBorder());
            labels[i].setHorizontalAlignment(JLabel.CENTER);

            add(labels[i]);
        }
    }

    /**
     * @param updatedLabels the updated labels to display
     */
    public void updateLabels(String[] updatedLabels) {
        if (updatedLabels.length != labels.length) {
            return;
        }
        for (int i = 0; i < labels.length; i++) {
            if (updatedLabels[i] == null) {
                labels[i].setText("---");
            }
            else {
                if (i != labels.length - 2) {
                    labels[i].setText(updatedLabels[i]);
                }
                else {
                    labels[i].setText("<html><B>" + updatedLabels[i] +
                                      "</B></html>");
                }
            }
        }
    }

    /**
     * set all the labels to "---"
     */
    public void clear() {
        for (int i = 0; i < labels.length; i++) {
            labels[i].setText("---");
        }
    }


}
